import Mock from 'mockjs'
import { config } from '../utils/request'
import { param2Obj } from '../utils/urlUtils'

var List = []
for (var i = 0; i < 100; i++) {
    List.push({
        // id: Mock.mock('@increment()'),
        nowshow: Mock.mock({ "array|1": ["已收费", "未收费",] }).array,
        type: Mock.mock({ "array|1": ["全部", "处方开立"] }).array,
        number: Mock.mock('@zip()'),
        username: Mock.mock('@cname()'),
        hourse: Mock.mock({ "array|1": ["全科", "内科", "外科",] }).array,
        doctor: Mock.mock('@cname()'),
        pianyi: Mock.mock('@natural(100,500)'),
        income: Mock.mock('@natural(100,500)'),
        nowincome: Mock.mock('@natural(100,500)'),
        yibao: Mock.mock('@natural(100,500)'),
        ip: Mock.mock('@natural(100,500)'),
        money: Mock.mock('@natural(100,500)'),
        zhifubao: Mock.mock('@natural(100,500)'),
        payv: Mock.mock('@natural(100,500)'),
        payy: Mock.mock('@natural(100,500)'),
        incomedate: Mock.mock('@datetime()'),
        user: Mock.mock('@cname()')
    })
}


export default {
    getstatistics: config => {
        console.log('config', param2Obj(config.url));
        var { keyword, page, pageSize } = param2Obj(config.url)
        //过滤元素的username中的关键词是否存在
        var res = List.filter(item => item.username.indexOf(keyword) != -1)
        //分页逻辑
        var resLimit = res.filter((item, index) => {
            return (page - 1) * pageSize <= index && index < page * pageSize
        })


        return {
            code: 200,
            msg: '请求成功',
            data: resLimit,
            total: List.length//返回一下总条数
        }
    }
}